package com.sunwoda.springbootredis.controller;

import com.sunwoda.springbootredis.entity.RequestOrder;
import com.sunwoda.springbootredis.entity.ResultEntity;
import com.sunwoda.springbootredis.result.Result;
import com.sunwoda.springbootredis.service.RequestOrderService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * (RequestOrder)表控制层
 *
 * @author makejava
 * @since 2021-09-23 14:22:04
 */
@RestController
@RequestMapping("requestOrder")
public class RequestOrderController {
    /**
     * 服务对象
     */
    @Resource
    private RequestOrderService requestOrderService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public RequestOrder selectOne(Integer id) {
        return this.requestOrderService.queryById(id);
    }

    /**
    * @Description: 导出
    * @Param:
    * @return:
    * @Author: SGR
    * @Date: 2021-09-23
    */
    @PostMapping(value = "/export")
    public void export(@RequestBody RequestOrder order,HttpServletResponse response){
        this.requestOrderService.export(order,response);
    }

    /**
    * @Description: 导入
    * @Param:
    * @return:
    * @Author: SGR
    * @Date: 2021-09-23
    */
    @PostMapping(value = "/OrderImport")
    public void OrderImport(@RequestBody MultipartFile file){
        this.requestOrderService.OrderImport(file);
    }

    /**
    * @Description: 获取订单列表
    * @Param:
    * @return:
    * @Author: SGR
    * @Date: 2021-09-24
    */
    @PostMapping(value = "/getList")
    public ResultEntity getList(@RequestBody RequestOrder re){
        List<RequestOrder> list = this.requestOrderService.getList(re);
        return Result.customSuccess(list);
    }

    /**
    * @Description: update
    * @Param:
    * @return:
    * @Author: SGR
    * @Date: 2021-09-24
    */
    @PutMapping(value = "/updateOrder")
    public ResultEntity updateOrder(@RequestBody RequestOrder re){
        int i = this.requestOrderService.updateOrder(re);
        if (i < 0){
            return Result.fail();
        }
        return Result.success();
    }

}
